
import { createRouter, createWebHistory } from 'vue-router'

import Layout from '../components/Layout.vue'
import { isHidden } from 'element-plus/es/components/focus-trap/index.mjs'



const publicRouters = [
    /** 登录注册相关页面 */
    {
        path: '',
        meta: {
            title: '校区通讯录',
        },
        redirect: '/contacts',
    },
    {
        path: '/login',
        meta: {
            title: '用户登录',
        },
        component: () => import('@/views/login/index.vue'),
    },
    {
        path: '/contacts',
        component: () => import('@/views/contacts/index.vue'),
    },
    {
        path: '/hello',
        component: () => import('@/views/hello/index.vue'),
    },
    {
        path: '/home',
        name: 'home',
        component: Layout,
        meta: {
            title: '首页',
            isMenu: true,
            icon: 'House'
        },
        redirect: '/home/index',
        children: [
            {
                path: 'index',
                component: () => import('@/views/home/index.vue'),
            },
        ]
    },
    {
        path: '/system',
        component: Layout,
        meta: {
            title: '系统设置',
            isMenu: true,
            icon: 'Setting'
        },
        redirect: '/system/index',
        children: [
            {
                path: 'index',
                meta: {
                    title: '首页',
                    hidden: true
                },
                component: () => import('@/views/system/index.vue'),
            },
            {
                path: 'role',
                meta: {
                    title: '角色',
                    hidden: false
                },
                component: () => import('@/views/system/role/index.vue'),
            },
            {
                path: 'user',
                meta: {
                    title: '用户',
                    hidden: false
                },
                component: () => import('@/views/system/user/index.vue'),
            },
        ]
    },

    {
        path: '/useinfo',
        component: Layout,
        meta: {
            title: '使用说明',
            isMenu: true,
            icon: 'Setting'
        },
        redirect: '/useinfo/index',
        children: [
            {
                path: 'index',
                meta: {
                    title: '腾讯',
                    target: '_blank',
                    hidden: false
                },
                // redirect: 'http://www.qq.com',
                component: () => import('@/views/hello/useInfo.vue'),
            },
            // {
            //     path: '163',
            //     meta: {
            //         title: '网易',
            //         hidden: false
            //     },
            //     redirect: 'http://www.163.com',
            //     //component: () => import('@/views/system/role/index.vue'),
            // },
            // {
            //     path: 'user',
            //     meta: {
            //         title: '淘宝',
            //         hidden: false
            //     },
            //     redirect: 'http://www.taobao.com',
            //     //component: () => import('@/views/system/user/index.vue'),
            // },
        ]
    },

    {
        path: '/ele',
        component: Layout,
        meta: {
            title: 'ElementPlus',
            isMenu: true,
            icon: 'ElemeFilled'
        },
        redirect: '/ele/index',
        children: [
            {
                path: 'icon',
                meta: {
                    title: '图标',
                    target: '_blank',
                    hidden: false
                },
                component: () => import('@/views/ele/icons.vue'),
            },
            {
                path: 'button',
                meta: {
                    title: '按钮',
                    target: '_blank',
                    hidden: false
                },
                // redirect: 'http://www.qq.com',
                component: () => import('@/views/ele/btns.vue'),
            },
            {
                path: 'form',
                meta: {
                    title: '表单',
                    target: '_blank',
                    hidden: false
                },
                component: () => import('@/views/ele/forms.vue'),
            },
            {
                path: 'draggables1',
                meta: {
                    title: '拖拽1',
                    target: '_blank',
                    hidden: false
                },
                component: () => import('@/views/ele/draggables001.vue'),
            },
            {
                path: 'draggables2',
                meta: {
                    title: '拖拽2',
                    target: '_blank',
                    hidden: false
                },
                component: () => import('@/views/ele/draggables002.vue'),
            },
            // {
            //     path: '163',
            //     meta: {
            //         title: '网易',
            //         hidden: false
            //     },
            //     redirect: 'http://www.163.com',
            //     //component: () => import('@/views/system/role/index.vue'),
            // },
            // {
            //     path: 'user',
            //     meta: {
            //         title: '淘宝',
            //         hidden: false
            //     },
            //     redirect: 'http://www.taobao.com',
            //     //component: () => import('@/views/system/user/index.vue'),
            // },
        ]
    },

    {
        path: '/ads',
        component: Layout,
        meta: {
            title: '通讯录管理',
            isMenu: true,
            icon: 'OfficeBuilding'
        },
        // redirect: '/ele/index',
        children: [
            {
                path: 'group',
                meta: {
                    title: '群组(部门)',
                    hidden: false
                },
                redirect: '/ads/group/index',
                children: [
                    {
                        path: 'index',
                        name: 'indexGroup',
                        meta: {
                            title: '群组(部门)列表',
                            hidden: true
                        },
                        component: () => import('@/views/ab/companygroup/list.vue'),
                    }, 
                    {
                        path: 'add',
                        name: 'addGroup',
                        meta: {
                            title: '添加群组(部门)',
                            hidden: true
                        },
                        component: () => import('@/views/ab/companygroup/add.vue'),
                    }, 
                    {
                        path: 'edit',
                        meta: {
                            title: '修改群组(部门)',
                            hidden: true
                        },
                        component: () => import('@/views/ab/companygroup/edit.vue'),
                    }, 
                ]
            },
            
            {
                path: 'phone',
                meta: {
                    title: '人员薄',
                    hidden: false
                },
                // component: () => import('@/views/ab/phonebook/index.vue'),
                redirect: '/ads/phone/index',
                children: [
                    {
                        path: 'index',
                        meta: {
                            title: '人员薄列表',
                            hidden: true
                        },
                        component: () => import('@/views/ab/phonebook/list.vue'),
                    }, 
                    {
                        path: 'add',
                        meta: {
                            title: '添加人员薄',
                            hidden: true
                        },
                        component: () => import('@/views/ab/phonebook/add.vue'),
                    }, 
                    {
                        path: 'edit',
                        meta: {
                            title: '修改人员薄',
                            hidden: true
                        },
                        component: () => import('@/views/ab/phonebook/edit.vue'),
                    }, 
                ]
            },
            
        ]
    },

    {
        path: '/:pathMatch(.*)',
        name: 'error',
        component: () => import('@/views/error/404.vue'),
        meta: {
            title: '404',
            isMenu: false,
        },
    }

]

const router = createRouter({
    history: createWebHistory(),
    routes: publicRouters
})

router.beforeEach((to, from, next) => {
    if(to.meta && to.meta.title) {
        document.title = to.meta.title
    }
    // console.log(to.path)
    const _path = to.path
    const res = router.getRoutes().filter((r) => {
        r.path === _path
    })
    //console.log(router.getRoutes())

    next()
})


export default router